//用户数据操作
/*jshint esversion: 9 */
import {localStorageX} from "storagex-js";

const state = localStorageX(  //全部本地化
    "UserContainer",
    {
        token:"",
        id:'',
        name:'',
    }
);

const mutations = {
    setUser(_state,user){  //写入用户信息
        ({
            tokens:_state.token,
            id:_state.id,
            loginName:_state.name,
        } = user);
    },
    resetUser(_state){  //清空用户
        _state.token = "";
        _state.id = "";
        _state.name = "";
    }
};

const actions = {
    // 用户登陆
    login({commit}) {
        commit('resetUser');
        Promise.resolve();
    },
    // 用户退出登陆
    resetUser({commit}) {
        commit('resetUser');
        return Promise.resolve();
    },
};

export default {
    namespaced: true,
    state,
    mutations,
    actions,
};

